using System;
using System.Collections.Generic;

namespace Core.Domain.Enums
{
  /*
   * 
   * Sample

  public class CacheKey : BaseEnumeration<CacheKey, string>
  {
    public static readonly CacheKey DalDataColumnInfo = new CacheKey("DalDataColumnInfo");
    public static readonly CacheKey DalLookup = new CacheKey("DalLookup");
    public static readonly CacheKey DalDataFilters = new CacheKey("DalDataFilters");

    static CacheKey()
    {
      Add(DalDataColumnInfo);
      Add(DalLookup);
      Add(DalDataFilters);
    }

    public CacheKey(string key) : base(key, key)
    {
    }

    public static IList<CacheKey> Items { get { return BaseItems; } }
  }

   * 
   * 
   * 
   * 
   * 
   * 
   * 
   */


  ///<summary>For Enumeration-style objects
  ///</summary>
  ///<typeparam name="TBase"></typeparam>
  ///<typeparam name="TValue"></typeparam>
  public abstract class BaseEnumeration<TBase, TValue> : IEnumeration where TBase : BaseEnumeration<TBase, TValue>
                                                                      where TValue : IEquatable<TValue>
  {
    private static TBase _defaultItem;

    ///<summary>
    ///  A list of the items in this enum
    ///</summary>
    protected static readonly IList<TBase> BaseItems = new List<TBase>();

    private readonly string _text;
    private readonly TValue _value;

    protected BaseEnumeration()
    {
    }

    protected BaseEnumeration(TValue value, string text)
    {
      _value = value;
      _text = text;
    }

    public TValue Value
    {
      get { return _value; }
    }

    public string Text
    {
      get { return _text; }
    }

    public Type ReturnedType
    {
      get { return typeof (TBase); }
    }

    public bool IsMutable
    {
      get { return false; }
    }

    public static TBase Default
    {
      get { return _defaultItem; }
    }

    public new bool Equals(object x, object y)
    {
      if (x == null || y == null)
      {
        return false;
      }
      return ((BaseEnumeration<TBase, TValue>) x)._value.Equals(((BaseEnumeration<TBase, TValue>) y)._value);
    }

    public int GetHashCode(object x)
    {
      return ((BaseEnumeration<TBase, TValue>) x)._value.GetHashCode();
    }


//    public object DeepCopy(object value)
//    {
//      if (value == null || value.GetType() != typeof (TValue))
//      {
//        return null;
//      }
//      return GetByValue((TValue) value);
//    }

    public object Replace(object original, object target, object owner)
    {
      return original;
    }

    public object Assemble(object cached, object owner)
    {
      return cached;
    }

    public object Disassemble(object value)
    {
      return value;
    }

    protected static void Add(TBase item)
    {
      BaseItems.Add(item);
    }

    protected static void AddAsDefault(TBase item)
    {
      BaseItems.Add(item);
      _defaultItem = item;
    }

    public override string ToString()
    {
      return _text;
    }
  }
}